**Kane Mason Wronski**
/* "WHO'S AT THE PARTY?"  JOURNAL OF POLITICS REPLICATIONS
CCES 2016 DATA CODING */
use "JOP_KMW_CCES.dta" file

***************************************
*Generate Perceptual Accuracy Measures
***************************************

**To what extent do citizens correctly perceive various groups to be aligned with the parties?
**CCES features 9 social groups -- women, men, whites, blacks, atheists, christians, muslims, hispanics, feminists
**relationship b/t each group and each party is asked with the following:
**"How closely do you associate the following groups with the Democratic/Republican Party? By “closely” we mean people who are most similar in their ideas, interests, and feelings."
**Each group/party rating has 4 response options: very closely, closely, somewhat closely, not closely at all


**each group/party rating on its own; each put on 0-1 scale where higher values = think "very close" to that party
**women
tab revUMS381d
gen women_dem = ((revUMS381d-1)/3)
tab revUMS381r
gen women_rep = ((revUMS381r-1)/3)

**men
tab revUMS382d
gen men_dem = ((revUMS382d-1)/3)
tab revUMS382r
gen men_rep = ((revUMS382r-1)/3)

**whites
tab revUMS383d
gen white_dem = ((revUMS383d-1)/3)
tab revUMS383r
gen white_rep = ((revUMS383r-1)/3)

**blacks
tab revUMS384d
gen black_dem = ((revUMS384d-1)/3)
tab revUMS384r
gen black_rep = ((revUMS384r-1)/3)

**atheists
tab revUMS385d
gen atheist_dem = ((revUMS385d-1)/3)
tab revUMS385r
gen atheist_rep = ((revUMS385r-1)/3)

**christians
tab revUMS386d
gen christ_dem = ((revUMS386d-1)/3)
tab revUMS386r
gen christ_rep = ((revUMS386r-1)/3)

**muslims
tab revUMS387d
gen muslim_dem = ((revUMS387d-1)/3)
tab revUMS387r
gen muslim_rep = ((revUMS387r-1)/3)

**hispanics
tab revUMS388d
gen hisp_dem = ((revUMS388d-1)/3)
tab revUMS388r
gen hisp_rep = ((revUMS388r-1)/3)

**feminists
revrs UMS389d
tab revUMS389d
gen fem_dem = ((revUMS389d-1)/3)
revrs UMS389r
tab revUMS389r
gen fem_rep = ((revUMS389r-1)/3)

**for each group, create a perceptual accuracy measure (close rep - close dem)
**positive values to 1 = you think that group is more aligned with Rep Party than Dem Party
**0 = think group is aligned equally with both parties
**negative values to -1 = you think group is more aligned with Dem Party than Rep Party

**Looking at the distributions of each group, see that <2% rate any Dem group as close to Rep Party
**<7% rated any Rep group as close to Dem Party 

**women
gen women_party = (women_rep - women_dem)
tab women_party
**men
gen men_party = (men_rep - men_dem)
tab men_party
**whites
gen white_party = (white_rep - white_dem)
tab white_party
**blacks
gen black_party = (black_rep - black_dem)
tab black_party
**atheists
gen atheist_party = (atheist_rep - atheist_dem)
tab atheist_party
**christians
gen christ_party = (christ_rep - christ_dem)
tab christ_party
**muslims
gen muslim_party = (muslim_rep - muslim_dem)
tab muslim_party
**hispanics
gen hisp_party = (hisp_rep - hisp_dem)
tab hisp_party
**feminists
gen fem_party = (fem_rep - fem_dem)
tab fem_party

**identifying a group as correctly being "close" to the right party
**0= completely wrong, 1=completely correct
**democratic aligned groups
gen women_party_acc = ((women_party+1)/2)
gen black_party_acc = ((black_party+1)/2)
gen atheist_party_acc = ((atheist_party+1)/2)
gen muslim_party_acc = ((muslim_party+1)/2)
gen hisp_party_acc = ((hisp_party+1)/2)
gen fem_party_acc = ((fem_party+1)/2)

**republican aligned groups
gen men_party_acc = (men_rep - men_dem)
replace men_party_acc = ((men_party_acc+1)/2)
gen white_party_acc = (white_rep - white_dem)
replace white_party_acc = ((white_party_acc+1)/2)
gen christ_party_acc = (christ_rep - christ_dem)
replace christ_party_acc = ((christ_party_acc+1)/2)

**Recode each group's perceptual accuracy into dichotomous variables
**coded 1 if the score on above continuous variable >.5, coded 0 if above continuous variable is <=.5
**democratic aligned groups
gen women_party_acc01 = .
recode women_party_acc01 .=1 if women_party_acc>.5 & women_party_acc<=1
recode women_party_acc01 .=0 if women_party_acc<=.5
tab women_party_acc01

gen black_party_acc01 = .
recode black_party_acc01 .=1 if black_party_acc>.5 & black_party_acc<=1
recode black_party_acc01 .=0 if black_party_acc<=.5
tab black_party_acc01

gen atheist_party_acc01 = .
recode atheist_party_acc01 .=1 if atheist_party_acc>.5 & atheist_party_acc<=1
recode atheist_party_acc01 .=0 if atheist_party_acc<=.5
tab atheist_party_acc01

gen muslim_party_acc01 = .
recode muslim_party_acc01 .=1 if muslim_party_acc>.5 & muslim_party_acc<=1
recode muslim_party_acc01 .=0 if muslim_party_acc<=.5
tab muslim_party_acc01

gen hisp_party_acc01 = .
recode hisp_party_acc01 .=1 if hisp_party_acc>.5 & hisp_party_acc<=1
recode hisp_party_acc01 .=0 if hisp_party_acc<=.5
tab hisp_party_acc01

gen fem_party_acc01 = .
recode fem_party_acc01 .=1 if fem_party_acc>.5 & fem_party_acc<=1
recode fem_party_acc01 .=0 if fem_party_acc<=.5
tab fem_party_acc01

egen dem_perceptual01 = rmean(women_party_acc01 black_party_acc01 atheist_party_acc01 muslim_party_acc01 hisp_party_acc01 fem_party_acc01)
tab dem_perceptual01

**republican aligned groups
gen men_party_acc01 = .
recode men_party_acc01 .=1 if men_party_acc>.5 & men_party_acc<=1
recode men_party_acc01 .=0 if men_party_acc<=.5
tab men_party_acc01

gen white_party_acc01 = .
recode white_party_acc01 .=1 if white_party_acc>.5 & white_party_acc<=1
recode white_party_acc01 .=0 if white_party_acc<=.5
tab white_party_acc01

gen christ_party_acc01 = .
recode christ_party_acc01 .=1 if christ_party_acc>.5 & christ_party_acc<=1
recode christ_party_acc01 .=0 if christ_party_acc<=.5
tab christ_party_acc01

egen rep_perceptual01 = rmean(men_party_acc01 white_party_acc01 christ_party_acc01)
tab rep_perceptual01

***************************************
*Obtaining x-axis values for Figure 1
***************************************

**Estimate of the extent to which each group is perceived as aligned with the Democratic/Republican parties.  
*** This would be on the x-axis. 
sum women_party, d
sum men_party, d
sum white_party, d
sum black_party, d
sum atheist_party, d
sum christ_party, d
sum muslim_party, d
sum hisp_party, d
sum fem_party, d


******************************************************************************
*SUPPLEMENTAL FIGURE D1 :  additive scales rather than factor scores
******************************************************************************

**create additive scale of closeness to "party-aligned" groups instead of factor scores
egen DemGroups_additive = rowmean(revUMS391 revUMS394 revUMS395 revUMS397 revUMS398 revUMS399)
replace DemGroups_additive = ((DemGroups_additive-1)/3)
tab DemGroups_additive

egen GOPgroups_additive = rowmean(revUMS392 revUMS393 revUMS396)
replace GOPgroups_additive = ((GOPgroups_additive-1)/3)
tab GOPgroups_additive

**r=0.27, p<.05 relationship between two sets of factor scores
pwcorr DemGroups_pfscore GOPgroups_pfscore DemGroups_additive GOPgroups_additive, sig star(.05)



******************************************************************************
*SUPPLEMENTAL FIGURE D2 :  Controlling for Personal Belonging to Party-Aligned Groups
******************************************************************************

**close to Dem groups -- if belonging to those groups
**ranges 0-1 where higher values is the composite of closeness to those aligned groups that you also belong to
**this excludes Feminist ratings since there is no "identity" measure of feminists to reference
gen closewomen=UMS391
omscore closewomen
replace closewomen= (rr_closewomen-1)/3
replace closewomen=. if female!=1

gen closeblack=UMS394
omscore closeblack
replace closeblack= (rr_closeblack-1)/3
replace closeblack=. if black!=1

gen closehisp=UMS398
omscore closehisp
replace closehisp= (rr_closehisp-1)/3
replace closehisp=. if hispanic!=1

gen closeatheist=UMS395
omscore closeatheist
replace closeatheist= (rr_closeatheist-1)/3
replace closeatheist=. if no_relig!=1

gen closemuslim= UMS397
omscore closemuslim
replace closemuslim= (rr_closemuslim-1)/3
replace closemuslim=. if muslim!=1

egen close_dem_groups = rmean(closewomen closeblack closehisp closeatheist closemuslim)
tab close_dem_groups

**close to Rep groups -- if belonging to those groups
gen closemen=UMS392
omscore closemen
replace closemen= (rr_closemen-1)/3
replace closemen=. if male!=1

gen closewhite=UMS393
omscore closewhite
replace closewhite= (rr_closewhite-1)/3
replace closewhite=. if white!=1

gen closechrist=UMS396 
omscore closechrist
replace closechrist= (rr_closechrist-1)/3
replace closechrist=. if christ==0

egen close_rep_groups =rmean(closemen closewhite closechrist)
tab close_rep_groups

**correlated 0.5 p<.05
pwcorr close_dem_groups close_rep_groups, sig star(.05)



******************************************************************************
*SUPPLEMENTAL TABLE D2 :  Group Sentiments and Partisanship Strength (by Party)
******************************************************************************

**create partisan identity strength scale where 0=leaner; .5=not so strong; 1=strong
gen pid_strength_new = .
recode pid_strength_new .=0 if pid7==3 | pid7==5
recode pid_strength_new .=.5 if pid7==2 | pid7==6
recode pid_strength_new .=1 if pid7==1 | pid7==7
tab pid_strength_new


******************************************************************************
*SUPPLEMENTAL FIGURE D5.  Group Sentiments and Groups’ Partisan Electoral Behavior
******************************************************************************
**Start with generating coefficients from the model that regresses 7-point PID (scaled 0-1) 
**on group closeness of each group separately, with each group coded 0-1
gen partyid01 = ((partyid-1)/6)
gen women_close = ((revUMS391-1)/3)
gen men_close = ((revUMS392-1)/3)
gen whites_close = ((revUMS393-1)/3)
gen blacks_close = ((revUMS394-1)/3)
gen atheist_close = ((revUMS395-1)/3)
gen christ_close = ((revUMS396-1)/3)
gen muslim_close = ((revUMS397-1)/3)
gen hisp_close = ((revUMS398-1)/3)
gen fem_close = ((revUMS399-1)/3)

**creating beta coefficients for the x-axis
reg partyid01 women_close dem_perceptual01 rep_perceptual01 polint age01 educ01 income01 gender black hisp other_race catholic mormon jewish other_rel no_relig attend01, robust
reg partyid01 men_close dem_perceptual01 rep_perceptual01 polint age01 educ01 income01 gender black hisp other_race catholic mormon jewish other_rel no_relig attend01, robust
reg partyid01 whites_close dem_perceptual01 rep_perceptual01 polint age01 educ01 income01 gender black hisp other_race catholic mormon jewish other_rel no_relig attend01, robust
reg partyid01 blacks_close dem_perceptual01 rep_perceptual01 polint age01 educ01 income01 gender black hisp other_race catholic mormon jewish other_rel no_relig attend01, robust
reg partyid01 atheist_close dem_perceptual01 rep_perceptual01 polint age01 educ01 income01 gender black hisp other_race catholic mormon jewish other_rel no_relig attend01, robust
reg partyid01 christ_close dem_perceptual01 rep_perceptual01 polint age01 educ01 income01 gender black hisp other_race catholic mormon jewish other_rel no_relig attend01, robust
reg partyid01 muslim_close dem_perceptual01 rep_perceptual01 polint age01 educ01 income01 gender black hisp other_race catholic mormon jewish other_rel no_relig attend01, robust
reg partyid01 hisp_close dem_perceptual01 rep_perceptual01 polint age01 educ01 income01 gender black hisp other_race catholic mormon jewish other_rel no_relig attend01, robust
reg partyid01 fem_close dem_perceptual01 rep_perceptual01 polint age01 educ01 income01 gender black hisp other_race catholic mormon jewish other_rel no_relig attend01, robust


